#include "SMyCanvas.h"

#include "FMyStyle.h"
#include "SMyButton.h"
#include "SMyListView.h"
#include "SMyTreeView.h"

void SMyCanvas::Construct(const FArguments& InArgs){
	SCanvas::Construct(InArgs);

	AddSlot()
		.Position(FVector2D(100, 100))
		.Size(FVector2D(100, 30))[
			SNew(SMyButton)
				.Text(FText::FromString(TEXT("确定")))
		];

	AddSlot()
		.Position(FVector2D(300, 100))
		.Size(FVector2D(100, 30))[
			SNew(SMyButton)
				.Text(FText::FromString(TEXT("取消")))
		];

	Options.Empty();
	Options.Add(MakeShareable(new FString(TEXT("苹果"))));
	Options.Add(MakeShareable(new FString(TEXT("梨"))));
	Options.Add(MakeShareable(new FString(TEXT("桔子"))));

	AddSlot()
		.Position(FVector2D(500, 100))
		.Size(FVector2D(100, 30))[
			SNew(SComboBox<TSharedPtr<FString>>)
				.OptionsSource(&Options)
				.OnGenerateWidget_Lambda([](TSharedPtr<FString> InValue) {
					return SNew(STextBlock).Text(FText::FromString(*InValue));
				})
				[
					SNew(STextBlock).Text_Lambda([this]() {
						if (CurrentSelected < 0 || CurrentSelected > Options.Num())
							return FText::FromString("");
						else
							return FText::FromString(*Options[CurrentSelected]);
					})
				]
				.OnSelectionChanged_Lambda([this](TSharedPtr<FString> NewOption, ESelectInfo::Type SelectType) {
					CurrentSelected = Options.Find(NewOption);
				})
		];
	
	// 添加水平布局
	AddSlot()
		.Position(FVector2D(100, 200))
		.Size(FVector2D(400, 30))[
			SNew(SHorizontalBox)
				+ SHorizontalBox::Slot()
				.FillWidth(2)[
					SNew(SMyButton)
						.Text(FText::FromString(TEXT("按钮1")))
				]
				+ SHorizontalBox::Slot()[
					SNew(SMyButton)
						.Text(FText::FromString(TEXT("按钮2")))
				]
				+ SHorizontalBox::Slot()[
					SNew(SMyButton)
						.Text(FText::FromString(TEXT("按钮3")))
				]
		];
	
	// 添加垂直布局
	AddSlot()
		.Position(FVector2D(700, 10))
		.Size(FVector2D(100, 120))[
			SNew(SVerticalBox)
				+SVerticalBox::Slot()
				.FillHeight(2)[
					SNew(SMyButton)
						.Text(FText::FromString(TEXT("按钮1")))
				]
				+ SVerticalBox::Slot()[
					SNew(SMyButton)
						.Text(FText::FromString(TEXT("按钮2")))
				]
				+ SVerticalBox::Slot()[
					SNew(SMyButton)
						.Text(FText::FromString(TEXT("按钮3")))
				]
		];
	
	// 添加树视图
	AddSlot()
		.Position(FVector2D(100, 300))
		.Size(FVector2D(100, 100))[
			SNew(SMyTreeView)
		];

	// 添加列表视图
	AddSlot()
		.Position(FVector2D(220, 300))
		.Size(FVector2D(100, 100))[
			SNew(SMyListView)
		];

	// 添加图像
	FMyStyle::ResetToDefault();
	AddSlot()
		.Position(FVector2D(850, 10))
		.Size(FVector2D(64, 64))[
			SNew(SImage)
				.Image(FMyStyle::Get().GetBrush("TrashCan"))
		];

	// 添加风格布局
	AddSlot()
		.Position(FVector2D(320, 300))
		.Size(FVector2D(128, 128))[
			SNew(SGridPanel)
			.FillColumn(0, 2)
			.FillColumn(1, 1)
			.FillRow(0, 2)
			.FillRow(1, 1)
			+ SGridPanel::Slot(0, 0)[
				SNew(SImage)
				.Image(FMyStyle::Get().GetBrush("TrashCan"))
			]
			+ SGridPanel::Slot(0, 1)[
				SNew(SImage)
				.Image(FMyStyle::Get().GetBrush("TrashCan"))
			]
			+ SGridPanel::Slot(1, 0)[
				SNew(SImage)
				.Image(FMyStyle::Get().GetBrush("TrashCan"))
			]
			+ SGridPanel::Slot(1, 1)[
				SNew(SImage)
				.Image(FMyStyle::Get().GetBrush("TrashCan"))
			]
		];
}
